package com.example.demo.service.impl;


import com.example.demo.dao.UserDao;
import com.example.demo.entity.UserEntity;
import com.example.demo.result.Result;
import com.example.demo.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class AutoStart implements ApplicationRunner {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private UserDao userDao;

    public String generateBoss(){
        if (userDao.selectBoss() == null){
            UserEntity userEntity = new UserEntity();
            userEntity.setAuthority(0);
            userEntity.setUsername("boss");
            userEntity.setPassword("0");
            userDao.enroll(userEntity);
            return "已成功生成管理员账号：‘boss’，密码：0";
        }
        return "管理员账号已存在！";
    }


    public String test (){

        return "成功了";
    }
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(generateBoss());
    }

}
